package com.ruoyi.ifmAge.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ifmAge.domain.IfmAge;
import com.ruoyi.ifmAge.service.IIfmAgeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 年龄Controller
 *
 * @author ruoyi
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/system/IfmAge")
public class IfmAgeController extends BaseController
{
    @Autowired
    private IIfmAgeService ifmAgeService;

    /**
     * 查询年龄列表
     */
    @PreAuthorize("@ss.hasPermi('system:IfmAge:list')")
    @GetMapping("/list")
    public TableDataInfo list(IfmAge ifmAge)
    {
        startPage();
        List<IfmAge> list = ifmAgeService.selectIfmAgeList(ifmAge);
        return getDataTable(list);
    }

    /**
     * 导出年龄列表
     */
    @PreAuthorize("@ss.hasPermi('system:IfmAge:export')")
    @Log(title = "年龄", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IfmAge ifmAge)
    {
        List<IfmAge> list = ifmAgeService.selectIfmAgeList(ifmAge);
        ExcelUtil<IfmAge> util = new ExcelUtil<IfmAge>(IfmAge.class);
        util.exportExcel(response, list, "年龄数据");
    }

    /**
     * 获取年龄详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:IfmAge:query')")
    @GetMapping(value = "/{ageId}")
    public AjaxResult getInfo(@PathVariable("ageId") Long ageId)
    {
        return success(ifmAgeService.selectIfmAgeByAgeId(ageId));
    }

    /**
     * 新增年龄
     */
    @PreAuthorize("@ss.hasPermi('system:IfmAge:add')")
    @Log(title = "年龄", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IfmAge ifmAge)
    {
        return toAjax(ifmAgeService.insertIfmAge(ifmAge));
    }

    /**
     * 修改年龄
     */
    @PreAuthorize("@ss.hasPermi('system:IfmAge:edit')")
    @Log(title = "年龄", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IfmAge ifmAge)
    {
        return toAjax(ifmAgeService.updateIfmAge(ifmAge));
    }

    /**
     * 删除年龄
     */
    @PreAuthorize("@ss.hasPermi('system:IfmAge:remove')")
    @Log(title = "年龄", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ageIds}")
    public AjaxResult remove(@PathVariable Long[] ageIds)
    {
        return toAjax(ifmAgeService.deleteIfmAgeByAgeIds(ageIds));
    }
}
